<template>
    <a-card :bordered="false">
        <!-- model弹窗 -->
        <a-modal v-model="visible1" title="统计" ok-text="确认" cancel-text="取消" :width="900">
            <div style="width:100%;height: 100%;background-color: rgb(255, 255, 255);"
                class="printId">
                <p>合计入库量为: {{ this.hejizongliang }}克</p>

            </div>
        </a-modal>

        <!-- model弹窗 -->
        <a-modal v-model="visible" title="Modal" ok-text="确认" cancel-text="取消" @ok="printpage ()"
            :width="900">
            <div style="width:100%;height: 100%;background-color: rgb(255, 255, 255);"
                class="printId">

                <div class="printId" id="printId">
                    <div>
                        <div style="text-align: center;">
                        </div>
                        <table :border="1" style="width:100%;text-align:center">
                            <tr>
                                <th style="width:16%; font-size: 20px;">货物名称</th>
                                <th style="width:16%; font-size: 13px;"> {{ this.shuju.rukuliang }}
                                </th>
                                <th style="width:16%; font-size: 20px;">仓库名称</th>
                                <th style="width:16%; font-size: 13px;">
                                    {{ this.shuju.cangkumingcheng}}</th>
                                <th style="width:100px; font-size: 20px;">申请人</th>
                                <th style="width:16%; font-size: 13px;">
                                    {{ this.shuju.rukurenxingming }}</th>
                            </tr>
                            <tr>
                                <th style="width:16%; font-size: 20px;">入库量(克)</th>
                                <th style="width:16%; font-size: 13px;">
                                    {{ this.shuju.huaxuepinmingcheng }}</th>
                                <th style="width:16%; font-size: 20px;">入库数(瓶)</th>
                                <th style="width:16%; font-size: 13px;">{{ this.shuju.rukupingshu}}
                                </th>
                                <th style="width:100px; font-size: 20px;">入库时间</th>
                                <th style="width:16%; font-size: 13px;">{{ this.shuju.rukushijan }}
                                </th>
                            </tr>
                            <tr>
                                <th style="width:16%; font-size: 20px;">司机姓名</th>
                                <th style="width:16%; font-size: 13px;">
                                    {{ this.shuju.sijixingming }}</th>
                                <th style="width:16%; font-size: 20px;">车牌号</th>
                                <th style="width:16%; font-size: 13px;">{{ this.shuju.chepaihao}}
                                </th>
                                <th style="width:100px; font-size: 20px;">购买厂家</th>
                                <th style="width:16%; font-size: 13px;">
                                    {{ this.shuju.goumaichangjia }}</th>
                            </tr>
                            <tr>
                                <th colspan="1" style="width:16%; font-size: 20px;">申请人部门</th>
                                <th colspan="2" style="width:16%; font-size: 13px;">
                                    {{ this.shuju.rukurenbumen }}</th>
                                <th colspan="1" style="width:16%; font-size: 20px;">驳回原因</th>
                                <th colspan="2" style="width:16%; font-size: 13px;">
                                    {{ this.shuju.bohuiyuanyin }}</th>
                            </tr>
                            <tr>
                                <th style="height:150px;font-size: 20px;" colspan="1">打开柜门拍照</th>
                                <th colspan="2"> <img style="height: 140px; width: 140px;"
                                        :src="this.url.url1+this.shuju.dakaiguimenpaizhao" /> </th>
                                <th colspan="1" style="font-size: 20px;">进入仓库拍照</th>
                                <th colspan="2"> </th>
                            </tr>
                            <tr>
                                <th colspan="6" style="height: 20px;"></th>
                            </tr>
                            <tr>
                                <th colspan="6">详细信息</th>
                            </tr>
                            <tr>
                                <th colspan="1">货架号</th>
                                <th colspan="1">批次号</th>
                                <th colspan="2">重量(克)</th>
                                <th colspan="2">二维码</th>
                            </tr>
                            <tr v-for="item in this.zidata" :key="item.id">
                                <th colspan="1">{{ item.huojiahao }}</th>
                                <th colspan="1">{{ item.picihao }}</th>
                                <th colspan="2">{{ item.zhongliang }}</th>
                                <th colspan="2">
                                    <img style="height: 140px; width: 140px;"
                                        :src="'http://localhost:8080/jeecg-boot/sys/common/static/'+item.erweima" />
                                </th>
                            </tr>
                        </table>
                    </div>

                </div>
            </div>
        </a-modal>

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="货物名称">
                            <a-select placeholder="请输入货物名称" v-model="queryParam.huaxuepinmingcheng"
                                :options="HuaxuepinList">

                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="仓库名称">
                            <a-select placeholder="请输入仓库名称" v-model="queryParam.cangkumingcheng"
                                :options="cangkuList"></a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <span style="float: left;overflow: hidden;"
                            class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery"
                                icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                            <a @click="handleToggleSearch" style="margin-left: 8px">
                                {{ toggleSearchStatus ? '收起' : '展开' }}
                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                            </a>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
            <a-button type="primary" icon="download"
                @click="handleExportXls('入库申请管理')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                :action="importExcelUrl" @change="handleImportExcel">
                <!-- <a-button type="primary" icon="import">导入</a-button> -->
            </a-upload>
            <!-- 高级查询区域 -->
            <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                @handleSuperQuery="handleSuperQuery"></j-super-query>
            <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown>

            <!--            <a-button @click="heji(selectedRowKeys)">合计</a-button>-->
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
                    style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap"
                :scroll="{x:true}" :columns="columns" :dataSource="dataSource"
                :pagination="ipagination" :loading="loading"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                @change="handleTableChange">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="getImgView(text)" height="25px" alt=""
                        style="max-width:80px;font-size: 12px;font-style: italic;" />
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small"
                        @click="downloadFile(text)">
                        下载
                    </a-button>

                </template>
                <!-- 入库状态 -->
                <template slot="rukuzhaungtai" slot-scope="text">
                    <a-tag v-if="text==0" color="blue">待审核</a-tag>
                    <a-tag v-if="text==1" color="green">二次审核通过</a-tag>
                    <a-tag v-if="text==2" color="green">核验完毕</a-tag>
                    <a-tag v-if="text==3" color="red">第一次驳回</a-tag>
                    <a-tag v-if="text==6" color="red">第二次驳回</a-tag>
                    <a-tag v-if="text==7" color="red">第三次驳回</a-tag>
                    <a-tag v-if="text==4" color="yellow">入库完成</a-tag>
                    <a-tag v-if="text==5" color="green">一次审核通过</a-tag>
                </template>

                <span slot="action" slot-scope="text, record">
                    <a @click="handleDetail(record)">详情</a>
                    <a-divider type="vertical" />
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                        <a-menu slot="overlay">
                            <a-menu-item v-if="record.rukuzhaungtai == 3">
                                <a @click="handleEdit(record)">编辑</a>
                            </a-menu-item>
                            <a-menu-item v-if="record.rukuzhaungtai==2">
                                <a @click="reject(record)">驳回</a>
                            </a-menu-item>
                            <a-menu-item v-if="record.rukuzhaungtai==2">
                                <a @click="rukuwancheng(record)">入库完成</a>
                            </a-menu-item>
                            <a-menu-item v-if="record.rukuzhaungtai == 3">
                                <a @click="reSubmit(record)">重新提交</a>
                            </a-menu-item>
                            <!-- <a-menu-item v-if="record.rukuzhaungtai==0">
                <a @click="shenhetongguo(record)">审核通过</a>
              </a-menu-item>
              <a-menu-item v-if="record.rukuzhaungtai==0">
                <a @click="shenhebohui(record)">审核驳回</a>
              </a-menu-item> -->
                            <!-- <a-menu-item >
                <a @click="dayin(record)">打印</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
                        </a-menu>
                    </a-dropdown>
                </span>

            </a-table>
        </div>
        <yzd-ru-ku-shenqing-modal ref="modalForm" @ok="modalFormOk" />
    </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YzdRuKuShenqingModal from './modules/YzdRuKuShenqingModal'
import '@/assets/less/TableExpand.less'
import { getAction, postAction, putAction } from '../../api/manage'

export default {
    name: "YzdShenqingguanliList",
    mixins: [JeecgListMixin],
    components: {
        YzdRuKuShenqingModal
    },
    data() {
        return {
            cangkuList: [],
            HuaxuepinList: [],
            visible1: false,
            visible: false,
            hejizongliang: 0.0,
            xianshi: true,

            description: '入库申请管理管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                /*{
                  title:'备案证上传',
                  align:"center",
                  dataIndex: 'gonganwenjian',
                  scopedSlots: {customRender: 'fileSlot'}
                },*/
                {
                    title: '入库状态',
                    align: "center",
                    dataIndex: 'rukuzhaungtai',
                    scopedSlots: { customRender: 'rukuzhaungtai' }
                },
                // {
                //   title:'货物类别',
                //   align:"center",
                //   dataIndex: 'huaxuepinleibie'
                // },
                {
                    title: '货物名称',
                    align: "center",
                    dataIndex: 'huaxuepinmingcheng'
                },
                // {
                //   title:'CAS号',
                //   align:"center",
                //   dataIndex: 'cashao'
                // },
                {
                    title: '入库时间',
                    align: "center",
                    sorter: true,
                    dataIndex: 'rukushijan',
                    customRender: function (text) {
                        return !text ? "" : (text.length > 10 ? text.substr(0, 19) : text)
                    }
                },
                /* {
                   title:'入库人员',
                   align:"center",
                   dataIndex: 'rukurenxingming'
                 },*/
                // {
                //   title:'入库部门',
                //   align:"center",
                //   dataIndex: 'rukurenbumen'
                // },
                // {
                //   title:'净含量(克)',
                //   align:"center",
                //   dataIndex: 'rukuliang'
                // },
                // {
                //   title:'回皮重量(克)',
                //   align:"center",
                //   dataIndex: 'huipizhongliang'
                // },
                // {
                //   title:'入库瓶数',
                //   align:"center",
                //   dataIndex: 'rukupingshu'
                // },
                /*{
                  title:'仓库名称',
                  align:"center",
                  dataIndex: 'cangkumingcheng'
                },*/
                /* {
                   title:'入场时间',
                   align:"center",
                   dataIndex: 'goumaishijian',
                   customRender:function (text) {
                     return !text?"":(text.length>10?text.substr(0,19):text)
                   }
                 },
                 {
                   title:'到期时间',
                   align:"center",
                   dataIndex: 'daoqishijian'
                 },
                 {
                   title:'签字',
                   align:"center",
                   dataIndex: 'qianzi',
                   scopedSlots: {customRender: 'imgSlot'}
                 },
                 {
                   title:'购买厂家',
                   align:"center",
                   dataIndex: 'goumaichangjia'
                 },*/
                {
                    title: '司机姓名',
                    align: "center",
                    dataIndex: 'sijixingming'
                },
                {
                    title: '车牌号',
                    align: "center",
                    dataIndex: 'chepaihao'
                },
                {
                    title: '公司名称',
                    align: "center",
                    dataIndex: 'gongsimingcheng'
                },
                /*  {
                    title:'进入仓库拍照',
                    align:"center",
                    dataIndex: 'jinrucangkupaizhao',
                    scopedSlots: {customRender: 'imgSlot'}
                  },
                  {
                    title:'打开柜门拍照',
                    align:"center",
                    dataIndex: 'dakaiguimenpaizhao',
                    scopedSlots: {customRender: 'imgSlot'}
                  },*/
                /* {
                   title:'驳回原因',
                   align:"center",
                   dataIndex: 'bohuiyuanyin'
                 },*/
                // {
                //   title:'仓库位置',
                //   align:"center",
                //   dataIndex: 'cangkuweizhi'
                // },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: "right",
                    width: 147,
                    scopedSlots: { customRender: 'action' },
                }
            ],
            url: {
                url1: "http://localhost:8080/jeecg-boot/sys/common/static/",
                getZi: "/yzd_rukuguanli/yzdShenqingguanli/getlistByid",
                wancheng: "/yzd_rukuguanli/yzdShenqingguanli/complete",
                shenhebohui: "/yzd_rukuguanli/yzdShenqingguanli/shenhebohui",
                shenhetongguo: "/yzd_rukuguanli/yzdShenqingguanli/shenhetongguo",
                list: "/yzd_rukuguanli/yzdShenqingguanli/mingxilist",
                edit: "/yzd_rukuguanli/yzdShenqingguanli/edit",
                delete: "/yzd_rukuguanli/yzdShenqingguanli/delete",
                deleteBatch: "/yzd_rukuguanli/yzdShenqingguanli/deleteBatch",
                exportXlsUrl: "/yzd_rukuguanli/yzdShenqingguanli/exportXls",
                importExcelUrl: "yzd_rukuguanli/yzdShenqingguanli/importExcel",
                getByIds: "yzd_rukuguanli/yzdShenqingguanli/getByIds",
                gethuaxuepinurl: "/yzd_jichuxinxi/yzdWeixianfeiwuxinxi/list",
                getcangkuurl: "/yzd_jichuxinxi/yzdZhucuncangkuxinxi/huoQuCangKu",
            },
            dictOptions: {},
            superFieldList: [],
            dataSource: [],
            shuju: [],
            zidata: {},
        }
    },
    created() {
        this.getSuperFieldList();
        this.gethuaxuepin();
        this.getcangku();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        }
    },
    methods: {
        getcangku() {
            getAction(this.url.getcangkuurl).then(res => {
                res.result.forEach(element => {
                    var a = {
                        value: element.cangkumingcehng,
                        label: element.cangkumingcehng
                    }
                    this.cangkuList.push(a)
                })
            })
        },
        gethuaxuepin() {
            getAction(this.url.gethuaxuepinurl).then(res => {
                res.result.records.forEach(element => {
                    let a = {}
                    console.log(element.huaxuepinmingcheng);
                    a.value = element.huaxuepinmingcheng
                    a.label = element.huaxuepinmingcheng
                    this.HuaxuepinList.push(a)
                })
            })
        },
        heji(item) {
            this.hejizongliang = 0.0
            postAction(this.url.getByIds, item).then(res => {
                console.log(res);
                res.result.forEach(element => {
                    this.hejizongliang += parseFloat(element.zhongliang)
                });
                this.visible1 = true;
            })
        },
        dayin(arr) {
            this.shuju = arr;
            this.visible = true;
            getAction(this.url.getZi, arr).then((res) => {
                this.zidata = res.result
            })
        },
        printpage() {
            // 这里我们是对局部打印做的演示
            // 首先获取局部html，也就是打印的区域
            const printHTML = document.querySelector('#printId').innerHTML;
            // 将打印的区域赋值，进行打印
            window.document.body.innerHTML = printHTML;
            window.print(); // 调用window打印方法
            window.location.reload(); // 打印完成后重新加载页面
        },
        rukuwancheng(arr) {
            postAction(this.url.wancheng, arr).then((res) => {
                if (res.success) {
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.loadData();
            })
        },
        shenhetongguo(arr) {
            this.xianshi = false,
                postAction(this.url.shenhetongguo, arr).then(res => {
                    if (res.success) {
                        this.$message.success(res.message)
                    } else {
                        this.$message.warning(res.message)
                    }
                    this.loadData();
                })
        },
        shenhebohui(arr) {
            this.xianshi = false,
                postAction(this.url.shenhebohui, arr).then(res => {
                    if (res.success == true) {
                        arr.rukuzhaungtai = 2
                    }
                    this.getSuperFieldList();
                })
        },
        reject(record) {//驳回
            record.rukuzhaungtai = 3
            putAction(this.url.edit, record).then((res) => {
                if (res.success) {
                    this.$message.success("驳回成功")
                } else {
                    this.$message.warning(res.message)
                }
                this.loadData()
            })
        },
        reSubmit(record) {//重新提交
            record.rukuzhaungtai = 2
            putAction(this.url.edit, record).then((res) => {
                if (res.success) {
                    this.$message.success("提交成功")
                } else {
                    this.$message.warning(res.message)
                }
                this.loadData()
            })
        },
        initDictConfig() {
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'gonganwenjian', text: '公安文件', dictCode: '' })
            fieldList.push({ type: 'string', value: 'rukuzhaungtai', text: '入库状态', dictCode: '' })
            fieldList.push({ type: 'string', value: 'huaxuepinleibie', text: '货物类别', dictCode: '' })
            fieldList.push({ type: 'string', value: 'huaxuepinmingcheng', text: '货物名称', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cashao', text: 'CAS号', dictCode: '' })
            fieldList.push({ type: 'date', value: 'rukushijan', text: '入库时间' })
            fieldList.push({ type: 'string', value: 'rukurenxingming', text: '入库人姓名', dictCode: '' })
            fieldList.push({ type: 'string', value: 'rukurenbumen', text: '入库人部门', dictCode: '' })
            fieldList.push({ type: 'BigDecimal', value: 'rukuliang', text: '入库量(克)', dictCode: '' })
            fieldList.push({ type: 'BigDecimal', value: 'huipizhongliang', text: '回皮重量(克)', dictCode: '' })
            fieldList.push({ type: 'int', value: 'rukupingshu', text: '入库瓶数', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cangkumingcheng', text: '仓库名称', dictCode: '' })
            fieldList.push({ type: 'date', value: 'goumaishijian', text: '购买时间' })
            fieldList.push({ type: 'string', value: 'goumaichangjia', text: '购买厂家', dictCode: '' })
            fieldList.push({ type: 'string', value: 'sijixingming', text: '司机姓名', dictCode: '' })
            fieldList.push({ type: 'string', value: 'chepaihao', text: '车牌号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'jinrucangkupaizhao', text: '进入仓库拍照', dictCode: '' })
            fieldList.push({ type: 'string', value: 'dakaiguimenpaizhao', text: '打开柜门拍照', dictCode: '' })
            fieldList.push({ type: 'string', value: 'bohuiyuanyin', text: '驳回原因', dictCode: '' })
            fieldList.push({ type: 'string', value: 'cangkuweizhi', text: '仓库位置', dictCode: '' })
            fieldList.push({ type: 'string', value: 'qianzi', text: '签字', dictCode: '' })
            this.superFieldList = fieldList
        }
    },
    mounted() {
        // this.gettudate();
        // this.initChartzhu();
        // this.initChartbing();
        // this.initChartzhe();
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>

